public class Test1 {
    public static void main(String[] args) {
        //insert()在指定位置插入
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("abcdef");
        stringBuffer.insert(1,1);
        System.out.println(stringBuffer);

        //reverse()反转字符串
        System.out.println(stringBuffer.reverse());
    }


    public static void main4(String[] args) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(1);
        stringBuilder.append("hello");
        stringBuilder.append(123);
        System.out.println(stringBuilder);
    }


    public static void main3(String[] args) {
        //将String转为StringBuilder
        String s = "abcdef";
        StringBuilder stringBuilder = new StringBuilder(s);

        //将StringBuilder转为String
        StringBuilder stringBuilder1 = new StringBuilder();
        stringBuilder1.append("hello");
        String s1 = stringBuilder1.toString();
        System.out.println(s1);
    }


    public static void main2(String[] args) {
        //使用StringBuilder 拼接
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("hello");
        stringBuilder.append(" gzc");
        String ret = stringBuilder.toString();
        System.out.println(ret);
    }


    public static void main1(String[] args) {
        String s = "hello";
        s = s + "world";
        System.out.println(s);
    }
}
